<template>
<div style="line-height: 50px; display:flex;">
  <div style="flex: 1;">
    <span :class="collapseBtnClass" style="cursor: pointer;font-size: 18px" @click="collapse"></span>
      <el-breadcrumb separator="/" style="display: inline-block; margin-left: 10px;">
        <el-breadcrumb-item :to="'/'">首页</el-breadcrumb-item>
        <el-breadcrumb-item >{{currentPathName}}</el-breadcrumb-item>
      </el-breadcrumb>

  </div>
  <el-dropdown style="width:150px; cursor:pointer; text-align: right" trigger="click" >
    <div style="display: inline-block;font-size: 15px">
      <img :src="user.avatarUrl" alt=""
           style="width: 30px;border-radius: 50%; position: relative;top: 10px;right: 5px"/>
      <span>  {{user.username}}</span><i class="el-icon-arrow-down" style="margin-left: 5px"></i>

    </div>
    <el-dropdown-menu slot="dropdown" style="text-align: center">
      <el-dropdown-item style="font-size: 15px;margin: 5px">
        <span style="text-decoration: none" @click="person">个人信息</span>
      </el-dropdown-item>
      <el-dropdown-item style="font-size: 15px;margin: 5px">
        <span style="text-decoration: none" @click="modifyPass">修改密码</span>
      </el-dropdown-item>
      <el-dropdown-item style="font-size: 15px;margin: 5px">
        <span style="text-decoration: none" @click="logout">退出</span>
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</div>
</template>

<script>
import router, {resetRouter} from "@/router";

export default {
  name: "Header",
  props: { //接受父组件传来的值
    collapseBtnClass:String,
    collapse: Function,
    user: Object
  },
  watch:{
    '$route':function (){//路由改变时更新头部显示的当前页面 面包屑
      this.currentPathName=localStorage.getItem("currentPathName")
    }
  },
  data(){
    return{
      currentPathName: '',
    }
  },
  created() {
    this.currentPathName=localStorage.getItem("currentPathName")
  },
  methods:{
    logout(){
      localStorage.removeItem("user")
      localStorage.removeItem("menus")
      router.push("/login")
      //重置路由
      resetRouter()
      this.$message.success("退出系统成功")
    },
    person(){
      router.push("/person")
    },
    modifyPass(){
      router.push("/modifyPass")
    }
  }
}
</script>

<style>
.el-breadcrumb__separator {
  margin: 0 9px;
  font-weight: 500;
  color: white;
}
</style>